﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MongoDB.Driver.Builders;
using MongoDBHelper;
using MyPet.Models;

namespace MyPet.Controllers
{
    public class HomeController : Controller
    {
        public HomeController()
        {
        }

        public JsonResult GetJson(int num, int page)
        {
            PagerInfo pagerInfo = new PagerInfo()
            {
                PageSize = num,
                Page = page
            };
            string[] strArrays = new string[] { "_id" };
            List<PetPhoto> result = MongoDBHelper.MongoDBHelper.GetAll<PetPhoto>("Animal", null, pagerInfo, SortBy.Descending(strArrays));
            return base.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetJsonByjingxuan(int num, int page)
        {
            string[] strArrays = new string[] { "likeCount" };
            List<PetPhoto> result = MongoDBHelper.MongoDBHelper.GetAll<PetPhoto>("JM", 50, SortBy.Descending(strArrays));
            JsonResult jsonResult = base.Json(
                from t in result
                orderby t.likeCount descending
                select t, JsonRequestBehavior.AllowGet);
            return jsonResult;
        }

        public ActionResult Index()
        {
            //var doc = new PetCategory();
            //doc.name = "狗";
            //doc.keyword = "狗";
            //doc.table = "Animal";
            //doc.beginHour = 8;
            //doc.endHour = 24;
            //var result = MongoDBHelper.MongoDBHelper.InsertOne("Category", doc);

            //var doc2 = new PetCategory();
            //doc2.name = "金毛";
            //doc2.parentId = doc._id.ToString();
            //doc2.keyword = "金毛";
            //doc2.table = "JM";
            //doc2.beginHour = 8;
            //doc2.endHour = 24;

            //var result2 = MongoDBHelper.MongoDBHelper.InsertOne("Category", doc2);

            return base.View();
        }

        public ActionResult jingxuan()
        {
            return base.View();
        }

        public ActionResult Test()
        {
            return base.View();
        }
    }
}
